export default{
    data(){
        return{
            tree:{
                showTreeDialog:false,
                treeType:'dept',//dept||district||deptUser
                treeTitle:'选择部门',
                treeData:[],//树数据
                deptTreeData:[],///部门树数据缓存
                districtTreeData:[],///区域树数据缓存
                deptUserTreeData:[],//部门人员树数据缓存

                isRadio:false,//默认多选
                deptNodeChecked:[{label:'',id:''}],
                districtNodeChecked:[{label:'',id:''}],
                deptUserNodeChecked:[{label:'',id:''}],

            },
        }
    },
    methods:{
        //打开树弹框
        onShowTree(treeType){
            this.$set(this.tree,'showTreeDialog',true)
            if(treeType==='dept'){
                this.tree.treeType='dept'
                this.getDepartmentTree()
                this.$set(this.tree,'treeTitle','选择部门')
                this.isRadio=true
            }else if(treeType==='district'){
                this.tree.treeType='district'
                this.getDistrictTree()
                this.$set(this.tree,'treeTitle','选择区域')
                this.isRadio=true
            }else if(treeType==='deptUser'){
                this.tree.treeType='deptUser'
                this.getDeptUserTree()
                this.$set(this.tree,'treeTitle','选择部门人员')
                this.isRadio=false
            }
        },


        //节点选择,单选&多选控制
        onNodeCheked(data, checked, indeterminate){
            //this.$refs.deptTree.setCheckedKeys([]);
           // this.$refs.deptTree.setCheckedKeys([data.id]);
            let checkedNode=this.$refs.eltree.getCheckedNodes();
            
            if(this.tree.treeType==='dept'){
                if(this.isRadio){
                    this.$set(this.tree,'deptNodeChecked',data)
                }else{
                    this.$set(this.tree,'deptNodeChecked',checkedNode)
                }
                
            }else if(this.tree.treeType==='district'){
                if(this.isRadio){
                    this.$set(this.tree,'districtNodeChecked',data)
                }else{
                    this.$set(this.tree,'districtNodeChecked',checkedNode)
                }
            }else if(this.tree.treeType==='deptUser'){
                if(this.isRadio){
                    this.$set(this.tree,'deptUserNodeChecked',data)
                }else{
                    this.$set(this.tree,'deptUserNodeChecked',checkedNode)
                }
                
            }

        },

        //确定
        onConfirmTree(){
            this.$set(this.tree,'showTreeDialog',false)
        },
        //取消
        onCancelTree(){
            this.$set(this.tree,'showTreeDialog',false)
        },

        //查询部门树
        getDepartmentTree(){
            if(this.tree.deptTreeData.length!=0){
                return 
            }
            this.$http.getDeptTree()
            .then((res)=>{
                this.$set(this.tree,'treeData',res.data.data)
            }).catch((err)=>{
                throw(err)
            })
        },

        //查询区域树
        getDistrictTree(){
            if(this.tree.districtTreeData.length!=0){
                return 
            }
            this.$http.getAreaTree()
            .then((res)=>{
                this.$set(this.tree,'treeData',res.data.data)
            }).catch((err)=>{
                throw(err)
            })
        },

        //查询部门人员树
        getDeptUserTree(){
            if(this.tree.deptUserTreeData.length!=0){
                return 
            }
            this.$http.getDeptUserTree()
            .then((res)=>{
                this.$set(this.tree,'treeData',res.data.data)
            }).catch((err)=>{
                throw(err)
            })
        },


    },

}